#region Using

using System;
using System.Custom.Generic;
using System.Drawing;
using CoCoon.Forms.Ribbon;
using Gizmox.WebGUI.Forms;

#endregion Using

namespace RibbonTest
{
    public partial class Form1 : Form
    {
        private RibbonBar _ribbonBar1;
        private SplitContainer _splitContainer1;

        private Label _helloLabel;

        public Form1()
        {
            InitializeComponent();
            _splitContainer1 = new SplitContainer();
            _splitContainer1.Dock = DockStyle.Fill;
            _splitContainer1.Panel1MinSize = 200;
            Controls.Add(_splitContainer1);

            _helloLabel = new Label();
            _helloLabel.Dock = DockStyle.Fill;
            _helloLabel.TextAlign = ContentAlignment.MiddleCenter;
            _helloLabel.Text = "Hello Gizmox";
            
            _splitContainer1.Panel1.Controls.Add(_helloLabel);

            InitRibbon();
        }

        private void InitRibbon()
        {
            _ribbonBar1 = new RibbonBar();
            Controls.Add(_ribbonBar1);

            var ribbonBarButtonItem = ImportantButton;
            RibbonBarLabelItem importantLabel;
            // With this set of extension methods you can fluently:
            _ribbonBar1
                // Add new page
                .AddPage("Controls")
                    // Add groups    
                    .AddGroup("Standard Buttons")
                        // Add buttons
                       .AddButton("Add", "Add button", "add", Clicked, tag: "Give me more!")
                       .AddButton("Edit", "Edit button", "Edit", Clicked, tag: "Edit")
                       // Assign event handlers and tags
                       .AddButton("delete", "delete button", "delete").OnClick(Clicked).Tag("It hurts!")
                       .AddStackItem()
                           .AddButton("Add", "Add button", "add")
                           .AddButton("Edit", "Edit button", "Edit")
                           .AddButton("delete", "delete button", "delete")
                    .AddGroup("Push Buttons")
                        //Mimics "Pushed state" of group of buttons 
                       .AddPushButton("Tile Horizontal", "Tile Horizontal", "TileHztl", pushGroup: "tile").Tag("TileHztl").OnClick(ChangeTile)
                       .AddPushButton("Tile Vertical", "Tile Vertical", "TileVert", pushGroup: "tile").Tag("TileVert").OnClick(ChangeTile)
                       .AddPushButton("TileOff", "Tile Off", "TileOff", pushGroup: "tile").Tag("TileOff").OnClick(ChangeTile).Push()
                       .AddStackItem()
                            // also in stacked mode 
                           .AddPushButton("Add Mode", " ", "add", pushGroup: "mode").Push()
                           .AddPushButton("Edit mode", " ", "edit", pushGroup: "mode")
                           .AddPushButton("Delete mode", " ", "delete", pushGroup: "mode")
                    .AddGroup("TextBox, Color, Search")
                        //Change width of items individually
                       .AddStackItem().Width(200)
                            .AddTextBox().Bind("Text",_helloLabel,"Text")
                            // Pick colors with ColorComboBox
                           .AddColorComboBox().OnSelectedColorChanged(ColorChanged)
                           // Search ....
                           .AddSearch("Search something", Search, Clear)
                    .AddGroup("DateTime picker and Label")
                       .AddStackItem().Width(50)
                           .AddLabel("")
                           // Label 
                           .AddLabel("From:")
                           .AddLabel("To:")
                        .AddStackItem()
                           .AddLabel("Date range:")
                           // Pick dates
                           .AddDateTimePicker(DateChanged).Tag("From")
                           .AddDateTimePicker(DateChanged).Tag("To")
                .AddPage("Features")
                       .AddGroup("Button")
                            // Disable items
                           .AddButton("Disabled Very Wide Button With Long Text", "", "Clear").Width(150).Disable()
                           // Assign to variables
                           .AddButton("Assigned To Variable", "", "Save").Assign(out ribbonBarButtonItem)
                           .AddButton("Click event", "", "Graf").Tag("Do not touch me!").OnClick(Clicked)
                        .AddGroup("Binding")
                            .AddStackItem()
                                // Bind them
                                .AddLabel("Change me").Assign(out importantLabel)
                                .AddTextBox().Bind("Text", importantLabel, "Text")
                                .AddTextBox().Bind("Text", importantLabel, "Text")
                            
                ;
            _ribbonBar1.ShowExpandButton = true;
        }

        protected RibbonBarButtonItem ImportantButton { get; set; }

        private void DateChanged(object sender, EventArgs e)
        {
            var c = sender as DateTimePicker;

            MessageBox.Show(c.Tag.ToString() + ": " + c.Value.ToLongDateString());
        }

        private void ColorChanged(object sender, EventArgs<Color> e)
        {
            _splitContainer1.Panel1.BackColor = e.Value;
        }

        private void ChangeTile(object sender, EventArgs e)
        {
            var ctl = sender as RibbonBarItem;
            if (ctl != null)
                switch (ctl.Tag.ToString())
                {
                    case "TileHztl":
                        _splitContainer1.Panel2Collapsed = false;
                        _splitContainer1.Orientation = Orientation.Horizontal;
                        break;

                    case "TileVert":
                        _splitContainer1.Panel2Collapsed = false;
                        _splitContainer1.Orientation = Orientation.Vertical;
                        break;

                    case "TileOff":
                        _splitContainer1.Panel2Collapsed = true;
                        _splitContainer1.Orientation = Orientation.Horizontal;
                        break;
                }
        }

        private void Clicked(object sender, EventArgs e)
        {
            var b = sender as RibbonBarItem;

            if (b != null) MessageBox.Show("Clicked:" + b.Tag);
        }

        private void Clear(object sender, EventArgs e)
        {
            MessageBox.Show("Search off");
        }

        private void Search(object sender, EventArgs<string> e)
        {
            MessageBox.Show(e.Value);
        }
    }
}